#ifndef __TEXEL_H__
#define __TEXEL_H__

#include <SDL/SDL.h>
#include <rapidxml.hpp>
#include "texture.h"
#include "config.h"
#include "error.h"
#include "objtable.h"

class ObjTable;

class Texel {
	public:
		Texel ();
		Texel (rapidxml::xml_node<> * node) throw(Error);
		virtual ~Texel ();
		
		void HandleTick(unsigned time);
		void EnableTicks ();
		void Detonate ();
		void Destroy();
		void Demolish();
		void Draw(SDL_Surface * screen, int x, int y);
		bool ReadyToExplode() {return bombExploding;};

		int bombDamage;
		int bombRadius;
		bool tickable;

		unsigned bombTime;
		int bombDelay;
		bool bombExploding;
	private:
		void GetStaticParams (rapidxml::xml_node<> * xml) throw(Error);
		void GetBombParams (rapidxml::xml_node<>* node) throw(Error);

		int state;
		int statesCount;
		int durability;
		int maxDurability;
		bool destroyable;
		bool empty;
		bool gatherable;
		bool detonateable;
		
		Texture texture;


	public: //Small inline routines
		void Dig (int damage);
		void Explode (int damage);
		bool IsDestroyable ();
		bool IsEmpty ();
		bool IsGatherable ();
		bool IsTickable() {return tickable;};
		ObjTable * table;


		int GetState ();
		void SetState (int state);
		void SetTbl(ObjTable * tbl) {table = tbl;};

		void GetSrcRect(SDL_Rect & rect);
};

#endif
